# 1. 服务端代码
from mcp.server.fastmcp import FastMCP
import aiofiles  # 异步操作文件


app = FastMCP("resource demo")

@app.resource(
    uri="file://yangshen.txt",
    name="yangshen",
    description="获取阳神大帝的相关介绍信息",
    mime_type="text/plain" # json是application/json,图片就是image/png、image/jpg 等等
)
async def yangshen():
    """
    获取知了课堂的相关介绍信息
    """
    async with aiofiles.open("../data/yangshen.txt", mode="r", encoding='utf-8') as fp: # 因为上下文都是异步执行的，所以打开文件也要aiofiles异步打开
        content = await fp.read()
    return content


if __name__ == '__main__':
    app.run(transport="sse")